  define([
  './menuitem',
  'backbone',
  'underscore',
  'jquery'
], function(ListMenuItemView, Backbone, _, $) {
  var ListMenuView = Backbone.View.extend({
    el: '.left-nav',
    tagName: 'ul',
    className: 'nav nav-list lists-nav',

    events: {

    },

    initialize: function() {
      //监听collection 取得数据事件触发渲染列表
      this.collection.on('add', this.renderMenuItem, this)
      this.collection.on('destroy', this.removeMenuItem, this)
    },

    renderMenuItem: function(model, collection, options) {
      var item = new ListMenuItemView({ model: model });
      if (options && options.at === 0)
        this.$el.prepend(item.render().el);
      else
        this.$el.append(item.render().el);

      if (!baker211b.views.activeListMenuItem) {
        baker211b.views.activeListMenuItem = item;
      }

      if (model.get('id') === baker211b.views.activeListMenuItem.model.get('id')) {
        item.open();
      }
    },

    removeMenuItem: function() {
      baker211b.views.activeListMenuItem.$el.remove();
    },

    render: function() {
      var $el = $(this.el), self = this;
      baker211b.routes.navigate('lists/' + baker211b.views.activeListMenuItem.model.get('id'));
      return this;
    }
  })

  return ListMenuView;
})